package edu.gatech.bsbmule.view;

import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

/**
 * @author bsb
 * this represents the town screen and implements the ITownScreen interface
 */
public class TownScreen extends JPanel implements ITownScreen{
	
	private JButton btnLO;
	
	private static TownScreen instance;
	
	public static TownScreen getInstance() {
		if (instance == null) {
			instance = new TownScreen();
		}
		return instance;
	}
	
	/**
	 * Create the panel.
	 */
	private TownScreen() {
		
		setBorder(new EmptyBorder(20,20,20,20));
		setLayout(new GridLayout(1 , 4));
		
		JButton btnStore = new JButton("STORE");
		btnStore.setFont(new Font("Tahoma", Font.PLAIN, 24));
		add(btnStore);
		btnStore.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				StoreScreen storeScreen = StoreScreen.getInstance(); 
				TownWindow.getInstance().setPanel(storeScreen); 
				TownWindow.getInstance().setTitle("Store");
			}
		});
		
		btnLO = new JButton("LAND OFFICE");
		btnLO.setFont(new Font("Tahoma", Font.PLAIN, 24));
		add(btnLO);
		
		JButton btnPub = new JButton("PUB");
		btnPub.setFont(new Font("Tahoma", Font.PLAIN, 24));
		add(btnPub);
		btnPub.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				TownWindow.getInstance().setPanel(new PubScreen());
				TownWindow.getInstance().setTitle("Pub");
			}
		});
		JButton btnExit = new JButton("EXIT");
		btnExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				TownWindow.getInstance().dispose();
			}
		});
		btnExit.setFont(new Font("Tahoma", Font.PLAIN, 24));
		add(btnExit);
	}
	
	/* (non-Javadoc)
	 * @see edu.gatech.bsbmule.view.ITownScreen#setLOButtonListener(java.awt.event.MouseAdapter)
	 */
	@Override
	public void setLOButtonListener(MouseAdapter e) {
		btnLO.addMouseListener(e);
	}

}
